//
//  ByCellMy.m
//  mijifen_ios
//
//  Created by mc on 2017/11/8.
//  Copyright © 2017年 itboye. All rights reserved.
//

#import "ByCellMy.h"

@implementation ByCellMy
{
    NSString    *_leftImg;
    NSString    *_titleStr;
    NSString    *_rightImg;
}

+ (instancetype)cellWithTableView:(UITableView*)tableView andTitle:(NSString *)title andLeftImg:(NSString *)leftImg andRightImg:(NSString *)rightImg{
    
    static NSString *cellIdentifier = @"ByCellMy";
    ByCellMy *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[self alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier andTitle:title andLeftImg:leftImg andRightImg:rightImg];
    }
    return cell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier andTitle:(NSString *) title andLeftImg:(NSString *)leftImg andRightImg:(NSString *)rightImg{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        _titleStr = title;
        _leftImg = leftImg;
        _rightImg = rightImg;
        self.selectionStyle = UITableViewCellSeparatorStyleNone;
        [self createViews];
    }
    return self;
}

- (void)createViews{
    UIImageView *leftImg = [[UIImageView alloc] init];
    [self addSubview:leftImg];
    [leftImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(10));
        make.top.equalTo(@(10));
        make.size.mas_equalTo(CGSizeMake(30, 30));
    }];
    leftImg.image = [UIImage imageNamed:_leftImg];
    
    UILabel *titleLabel = [[UILabel alloc] init];
    [self addSubview:titleLabel];
    CGFloat width = [_titleStr getSizeOfString:16].width + 20;
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(leftImg.mas_right).offset(10);
        make.top.equalTo(@(10));
        make.size.mas_equalTo(CGSizeMake(width, 30));
    }];
    titleLabel.text = _titleStr;
    titleLabel.font = FONT(16);
    
    if ([_titleStr isEqualToString:@"店铺收款码"]) {
        UIImageView *rightImg = [[UIImageView alloc] init];
        [self addSubview:rightImg];
        [rightImg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(@(-10));
            make.top.equalTo(@(10));
            make.size.mas_equalTo(CGSizeMake(30, 30));
        }];
        rightImg.image = [UIImage imageNamed:_rightImg];
    }else{
        UISwitch *rightSwitch = [[UISwitch alloc] init];
        [self addSubview:rightSwitch];
        [rightSwitch mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(@(-10));
            make.top.equalTo(@(10));
            make.size.mas_equalTo(CGSizeMake(60, 30));
        }];
        rightSwitch.onTintColor = BY_THEME_COLOR;
        rightSwitch.thumbTintColor = BY_TEXT_COLOR;
    }
}

@end
